import 'package:flutter/material.dart';

/**
 * 无线循环
 */
class PageviewFullPage extends StatefulWidget {
  const PageviewFullPage({super.key});

  @override
  State<PageviewFullPage> createState() => _PageviewFullPageState();
}

class _PageviewFullPageState extends State<PageviewFullPage> {
  List<Widget> list = [];

  @override
  void initState() {
    super.initState();
    for (int a = 0; a < 10; a++) {
      list.add(Center(
        child: Text(
          '无线加载第${a + 1}屏',
          style: TextStyle(fontSize: 40, color: Colors.red),
        ),
      ));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('data'),
      ),
      body: PageView(
        scrollDirection: Axis.vertical,
        children: list,
        //页面滑动时触发
        onPageChanged: (index) {
          if (index + 2 == 10) {
            setState(() {
              //无线循环
              for (int b = 0; b < 10; b++) {
                list.add(Center(
                  child: Text(
                    '无线加载第${b + 1}屏',
                    style: TextStyle(fontSize: 30, color: Colors.yellow),
                  ),
                ));
              }
            });
          }
        },
      ),
    );
  }
}
